package com.erp.collect.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.common.core.web.oldController.BaseController;
import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.erp.collect.domain.vo.ErpCollectProductAVo;
import com.erp.collect.domain.bo.ErpCollectProductABo;
import com.erp.collect.service.IErpCollectProductAService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

/**
 * 采集商品a 从1688采集 由complianceAe方法放入
 *
 * @author erp
 * @date 2024-05-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/collect/collectProductA")
public class ErpCollectProductAController extends BaseController {

    private final IErpCollectProductAService iErpCollectProductAService;

    /**
     * 查询采集商品a 从1688采集 由complianceAe方法放入列表
     */
    @SaCheckPermission("collect:collectProductA:list")
    @GetMapping("/list")
    public TableDataInfo<ErpCollectProductAVo> list(ErpCollectProductABo bo, PageQuery pageQuery) {
        return iErpCollectProductAService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取采集商品a 从1688采集 由complianceAe方法放入详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("collect:collectProductA:query")
    @GetMapping("/{id}")
    public R<ErpCollectProductAVo> getInfo(@NotNull(message = "主键不能为空")
                                           @PathVariable Long id) {
        return R.ok(iErpCollectProductAService.queryById(id));
    }

    /**
     * 新增采集商品a 从1688采集 由complianceAe方法放入
     */
    @SaCheckPermission("collect:collectProductA:add")
    @Log(title = "采集商品a 从1688采集 由complianceAe方法放入", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpCollectProductABo bo) {
        return toAjax(iErpCollectProductAService.insertByBo(bo));
    }

    /**
     * 修改采集商品a 从1688采集 由complianceAe方法放入
     */
    @SaCheckPermission("collect:collectProductA:edit")
    @Log(title = "采集商品a 从1688采集 由complianceAe方法放入", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCollectProductABo bo) {
        return toAjax(iErpCollectProductAService.updateByBo(bo));
    }

    /**
     * 删除采集商品a 从1688采集 由complianceAe方法放入
     *
     * @param ids 主键串
     */
    @SaCheckPermission("collect:collectProductA:remove")
    @Log(title = "采集商品a 从1688采集 由complianceAe方法放入", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpCollectProductAService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    @GetMapping("/getCollectProductAAllInfoById/{collectProductId}")
    public R<Object> getCollectProductAAllInfoById(@PathVariable("collectProductId") Long collectProductId) {
        return iErpCollectProductAService.getCollectProductAAllInfoById(collectProductId);
    }

    @GetMapping("/sendCollectUpdateResult/{collectProductId}/{type}/{msg}")
    public R<Object> sendCollectUpdateResult(
            @PathVariable("collectProductId") Long collectProductId,
            @PathVariable("type") Integer type,
            @PathVariable("msg") String msg
    ) {
        return iErpCollectProductAService.sendCollectUpdateResult(collectProductId, type, msg);
    }
}
